package com.ytd.smartcanteen.weighting.bean;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import com.ytd.common.util.DeviceUtil;

import cn.hutool.crypto.SmUtil;
import java.io.Serializable;
import java.util.UUID;


@Entity
public class OrderBean implements Serializable {
    @PrimaryKey
    @NonNull
    public String orderId = UUID.randomUUID().toString();
    public String trayId;
    public String deviceNo = DeviceUtil.getDeviceSN();
    public String foodWeight;
    public String foodId;
    public String mealTimeId;
    public String startTime;
    public String endTime;
    public int uploadState = 0;

    /**
     * userId : 1628239468593025024
     * calcType : 0
     * onePortionWeight : 100
     * floatingWeight : 30
     * mealTimeTypeCode : 1
     * mealStartTime : 12:00
     * mealEndTime : 14:00
     * price : 5
     * priceUnit : 元
     * weight : 100
     * weightUnit : 克
     * whetherLimitWeightOfTake : 1
     * limitWeightOfTake : 500
     * sign : 97515a2cad6e7c47cd05027e459f6a6cdaa8c35c46ed6450e5bc665623f7bbb6
     */

    public String categoryId;
    public String categoryName;
    public String foodName;
    public String userId;

    public String mealStartTime;
    public String mealEndTime;
    public String mealTimeName;
    public String mealTimeTypeCode;
    public String price;
    public String priceUnit;
    public int clipWeight;

    public String weightUnit;
    public int startingWeight = -1;
    public String sign;

    public int calcType = 0;
    public int onePortionWeight = 0;
    public int floatingWeight = 0;
    public int weight = 0;
    public int whetherLimitWeightOfTake = 0;
    public int limitWeightOfTake = 0;

    public void setFood(MealInfo mealInfo) {
        categoryId = mealInfo.foodCategoryId;
        categoryName = mealInfo.foodCategoryName;
        foodName = mealInfo.foodName;
        mealStartTime = mealInfo.mealStartTime;
        mealEndTime = mealInfo.mealEndTime;
        price = mealInfo.price;
        priceUnit = mealInfo.priceUnit;
        weightUnit = mealInfo.weightUnit;
        mealTimeTypeCode = mealInfo.mealTimeTypeCode;

        calcType = mealInfo.calcType;
        onePortionWeight = mealInfo.onePortionWeight;
        floatingWeight = mealInfo.floatingWeight;
        weight = mealInfo.weight;
        startingWeight = mealInfo.startingWeight;
        whetherLimitWeightOfTake = mealInfo.whetherLimitWeightOfTake;
        limitWeightOfTake = mealInfo.limitWeightOfTake;
        clipWeight = mealInfo.clipWeight;
    }


    @Override
    public String toString() {
        return "OrderBean{" +
            "orderId='" + orderId + '\'' +
            ", trayId='" + trayId + '\'' +
            ", deviceNo='" + deviceNo + '\'' +
            ", foodWeight='" + foodWeight + '\'' +
            ", foodId='" + foodId + '\'' +
            ", mealTimeId='" + mealTimeId + '\'' +
            ", startTime='" + startTime + '\'' +
            ", endTime='" + endTime + '\'' +
            '}';
    }

    public void createSign() {
        StringBuilder builder = new StringBuilder();
        builder.append(orderId)
            .append(trayId)
            .append(foodId)
            .append(mealTimeId)
            .append(foodWeight);
        sign = SmUtil.sm3(builder.toString());
    }
}
